package com.example.dragon.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.dragon.bean.OrderBean;
import com.example.dragon.common.Common;
import com.example.dragon.dialog.MessageDialog;
import com.example.dragon.dialog.WaitDialog;
import com.example.dragon.untis.CircleImageView;
import com.example.dragon.xmf.MainActivity;
import com.example.dragon.xmf.R;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;

/**
 * Created by Dragon on 2017/6/24.
 */

public class CanceledAdpter extends RecyclerView.Adapter {
    private List<OrderBean> mcomList = new ArrayList<>();
    Context mcontext;
    private MessageDialog messageDialog;
    WaitDialog mwaitDialog;
    public CanceledAdpter(Context mcontext, List<OrderBean> mcomList) {
        this.mcontext = mcontext;
        this.mcomList=mcomList;
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    private PdDriverAdpter.OnItemClickLitener mOnItemClickLitener;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mcontext).inflate(R.layout.cancele_iten_layout, parent, false);
        mwaitDialog = new WaitDialog(mcontext,"2");
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final OrderBean item = mcomList.get(position);

        final ViewHolder viewHolder = (ViewHolder) holder;
        if (item != null) {
            viewHolder.canaddress.setText(item.getAddress());
            viewHolder.candate.setText(item.getWorktime());
            viewHolder.canoid.setText(item.getOrders_id());
            if (mOnItemClickLitener != null) {
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = viewHolder.getLayoutPosition();
                        mOnItemClickLitener.onItemClick(viewHolder.itemView, pos);
                    }
                });

                holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        int pos = viewHolder.getLayoutPosition();
                        mOnItemClickLitener.onItemLongClick(viewHolder.itemView, pos);
                        return false;
                    }
                });
            }        }
    }
    @Override
    public int getItemCount() {
        return mcomList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView canoid,canaddress,candate,cmdname;
        CircleImageView cmavater;
        public ViewHolder(View itemView) {
            super(itemView);
            canoid = (TextView)itemView.findViewById(R.id.canoidText);
            cmavater = (CircleImageView)itemView.findViewById(R.id.cannavter);
            canaddress =(TextView)itemView.findViewById(R.id.canaddressText);
            candate =(TextView)itemView.findViewById(R.id.candateText);
            cmdname =(TextView)itemView.findViewById(R.id.candanameText);
        }
    }
}
